package cn.lyjuan.android.demofive.frame.tpl.demo;

import android.os.Bundle;
import android.support.annotation.Nullable;
import android.view.View;

import cn.lyjuan.android.demofive.R;
import cn.lyjuan.android.demofive.frame.tpl.RecyclerViewFragmentImpl;
import cn.lyjuan.android.demofive.frame.tpl.TplRecyclerAdapter;
import cn.lyjuan.android.mylibrary.context.RealmApplication;
import io.realm.Realm;

/**
 * Created by chad on 13/11/2017.
 */

public class RecyclerFragment extends RecyclerViewFragmentImpl
{
    protected Realm realm;

    @Override
    public void onCreate(@Nullable Bundle savedInstanceState)
    {
        realm = RealmApplication.realm();

        super.onCreate(savedInstanceState);
    }

    @Override
    protected void loadViewModel()
    {
        viewModel = new RecyclerViewModel(realm, rv);
        adapter = new TplRecyclerAdapter(viewModel, R.layout.frame_tpl_list_item, getActivity().getLayoutInflater());
        viewModel.setAdapter(adapter);
    }

    @Override
    protected int layoutId()
    {
        return R.layout.frame_tpl_recycler_fragment;
    }

    @Override
    protected int recyclerViewId()
    {
        return R.id.recycler_view;
    }

    @Override
    protected void recyclerViewSetting(View view)
    {
        super.recyclerViewSetting(view);



    }

    @Override
    public void onStop()
    {
        super.onStop();
        if (null != realm && !realm.isClosed())
            realm.close();
    }
}
